<?php
namespace app\app\model;
use think\Model;
use think\Db;

class Goods extends Model{

	public $store_id;

	/**
	 * [getOne description]
	 * @param  [type] $name [description]
	 * @return [type]       [description]
	 */
	public function getOne($name)
	{
		$goods = $this->where('name','like','%'.$name.'%')->find();
		return $goods;
	}

	/**
	 * [getAll description]
	 * @return [type] [description]
	 */
	public function getAll($shop){			
		$where['store_id'] = array('eq',$this->store_id);
		$data = Db::name('goods_cate')->field('id,name,concat("'.config('IMG_HEAD').'",image) image')->where($where)->select();
		//按分类
		if( $data ){
			foreach( $data as $k => $v ){
				$goods = $this->field('id,name,description,price,sales,concat("'.config('IMG_HEAD').'",image) image')->where('cate_id','eq',$v['id'])->select();
				foreach($goods as $k1 => $v1){
					$goods[$k1]['number'] = 0;
					if( !empty($shop) && !empty($shop['pocket']) ){
						foreach($shop['pocket'] as $m => $n){
							if($n->id == $v1['id']){
								$goods[$k1]['number'] = $n->number;
							}
						}
					}
				}
				$data[$k]['goods_list'] = $goods;
			}
		}else{
			$data = [];
		}
		return $data;			
	}



}